﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using DataBaseTable;
public partial class Manage_Golbal_AddAdmin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void add_Click(object sender, EventArgs e)
    {
        AdminTable hasadmin = new AdminTable(this.UserName.Text.Trim());
        if (hasadmin.ID != 0)
        {
            ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('此管理员已经存在');</script>");
            return;
        }
        AdminTable admin = new AdminTable();
        admin.UserName = this.UserName.Text.Trim();
        admin.TureName = this.TureName.Text.Trim();
        admin.UserRole = "admin";
        admin.UserPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(this.UserPassWord.Text.Trim(), "MD5").ToLower();
        try
        {
            admin.Insert();
            ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('添加管理员成功');window.location.href='Golbal_AdminListaspx.aspx';</script>");
        }
        catch
        {
            ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('新增管理员失败');</script>");
        }
    }
}